package com.fjec.paid.rabbitmq.provider;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class YsPayDelayQueryProvoder {
    @Value("${fjec.paid.yspaydelayquery.exchange.name}")
    private String exchangeName;

    @Value("${fjec.paid.yspaydelayquery.router.key}")
    private String routingKey;

    // 延时时间，单位秒
//    @Value("${fjec.paid.yspaydelayquery.delay.value}")
//    private Integer delay;

    @Resource(name = "ysPayDelayQueryTemplate")
    private RabbitTemplate ysPayDelayQueryTemplate;

    // 银盛支付结果主动查询
    public void sendYsPayDelayQuery(String orderId, Integer delay) {
        MessageProperties props = new MessageProperties();
        props.setHeader("delay", delay * 1000);
        Message msg = new Message(orderId.getBytes(), props);
        ysPayDelayQueryTemplate.convertAndSend(exchangeName, routingKey, msg);
    }

}
